﻿//29014.2 ISYC 201 - 01 - 三角刀片 - 形状T - GB / T 2076

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{
    class class_ISYC_201_01
    {
        public static void ISYC_201_01(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();

            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double tic = Convert.ToDouble(data["ic"]);
            //double scale = Convert.ToDouble(data["scale"]); //放大系数
            double offset = 10;

            /*if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }*/
            double scale = 1;


            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            // int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);
            string path = Convert.ToString(data["path"]);
            double le = 2 * ic * Math.Cos(pi / 6);
            double ictc = Convert.ToDouble(data["ictc"]);
            double stc = Convert.ToDouble(data["stc"]);
            //double d1tc = Convert.ToDouble(data["d1tc"]);
            double dxc = 0.8;

            double krins = Convert.ToDouble(data["krins"]);//主切削刃角
            double kch = Convert.ToDouble(data["kch"]);//角倒角角度
            double bs = Convert.ToDouble(data["bs"]);//修光刃长度（对应KRINS角）
            //double bch = Convert.ToDouble(data["bch"]);//角倒角长度（对应KCH角）

            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = fun.Polar(p1, pi / 6, ic);
            Vector2 p2 = fun.Polar(p1, 0, le);
            Vector2 p3 = fun.Polar(p1, pi / 3, le);

            //正三边形刀片，适用于T形刀片----------------------------------------------------------------------------------------------------------            
            if (bs == 0)
            {
                Vector2 p1p = fun.Polar(p1, pi / 6, 2 * re);
                Vector2 p2p = fun.Polar(p2, 5 * pi / 6, 2 * re);
                Vector2 p3p = fun.Polar(p3, -0.5 * pi, 2 * re);
                Vector2 p4 = fun.Polar(p1p, 5 * pi / 6, re);
                Vector2 p5 = fun.Polar(p1p, -0.5 * pi, re);
                Vector2 p6 = fun.Polar(p2p, -0.5 * pi, re);
                Vector2 p7 = fun.Polar(p2p, pi / 6, re);
                Vector2 p8 = fun.Polar(p3p, pi / 6, re);
                Vector2 p9 = fun.Polar(p3p, 5 * pi / 6, re);

                Vector2 p20 = fun.Polar(p0, 0, 2 * ic);
                Vector2 p21 = new Vector2(p20.X, p3p.Y + re);

                Vector2 p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
                Vector2 p24 = new Vector2(p20.X, p1.Y);
                Vector2 p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));

                Vector2 v1 = fun.Polar(p0, -150 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);
                Vector2 v2 = fun.Polar(p0, -30 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);
                Vector2 v3 = fun.Polar(p0, 90 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);

                if (cb == 1 || cb == 2)//断屑槽为1或2（默认为0）
                {
                    Line line15 = new Line(v1, v2);
                    line15.Lineweight = Lineweight.W25;
                    line15.Layer = additionalline;
                    dxf.AddEntity(line15);
                    Line line16 = new Line(v2, v3);
                    line16.Lineweight = Lineweight.W25;
                    line16.Layer = additionalline;
                    dxf.AddEntity(line16);
                    Line line17 = new Line(v1, v3);
                    line17.Lineweight = Lineweight.W25;
                    line17.Layer = additionalline;
                    dxf.AddEntity(line17);
                }

                insert.inserthole1(dxf, p0, v2, v3, p20, p21, scale, data);

                Arc arc3 = fun.DrawArc(p8, p3p, p9);

                LwPolyline poly11 = new LwPolyline();
                poly11.Vertexes.Add(new LwPolylineVertex(p4));
                poly11.Vertexes[0].Bulge = Math.Tan((pi - epsr) / 4);
                poly11.Vertexes.Add(new LwPolylineVertex(p5));
                poly11.Vertexes.Add(new LwPolylineVertex(p6));
                poly11.Vertexes[2].Bulge = Math.Tan((pi - epsr) / 4);
                poly11.Vertexes.Add(new LwPolylineVertex(p7));
                poly11.Vertexes.Add(new LwPolylineVertex(p8));
                poly11.Vertexes[4].Bulge = Math.Tan((pi - epsr) / 4);
                poly11.Vertexes.Add(new LwPolylineVertex(p9));
                poly11.IsClosed = true;
                fun.PolyFill(dxf, poly11, 0.3, contour);

                Line line12 = new Line(p1, p2);
                line12.Lineweight = Lineweight.W25;
                line12.Layer = additionalline;
                dxf.AddEntity(line12);
                Line line13 = new Line(p2, p3);
                line13.Lineweight = Lineweight.W25;
                line13.Layer = additionalline;
                dxf.AddEntity(line13);
                Line line14 = new Line(p1, p3);
                line14.Lineweight = Lineweight.W25;
                line14.Layer = additionalline;
                dxf.AddEntity(line14);



                Line cenline1 = new Line(fun.Polar(p0, pi, ic / 2 * 1.5), fun.Polar(p0, 0, ic / 2 * 1.5));
                Line cenline2 = new Line(fun.Polar(p0, 0.5 * pi, ic * 1.1), fun.Polar(p0, -0.5 * pi, ic / 2 * 1.5));
                Line cenline3 = new Line(fun.Polar(p20, 0, 3), fun.Polar(p20, pi, s + 3));
                Circle dotcircle1 = new Circle(p0, ic / 2);
                cenline1.Layer = center;
                cenline2.Layer = center;
                cenline3.Layer = center;
                dotcircle1.Layer = refin;
                cenline1.Linetype = Linetype.Center;
                cenline2.Linetype = Linetype.Center;
                cenline3.Linetype = Linetype.Center;
                dotcircle1.Linetype = Linetype.DashDot;
                dxf.AddEntity(cenline1);
                dxf.AddEntity(cenline2);
                dxf.AddEntity(cenline3);
                dxf.AddEntity(dotcircle1);

                //fun.jz(dxf, fun.Polar(fun.Polar(p0, 0, ic / 2), -90 * pi / 180, 25), 0, 3, "A");

                //标注---------------------------------------------------------------------------
                double height = 1 * scale;
                double arrowsize = 1 * scale;
                double exline = 0.5 * scale;
                DimensionStyle dimensionStyle = new DimensionStyle("sd");
                dimensionStyle.ArrowSize = 1.6;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = 0.5;

                if (DIM == 0)
                {
                    //IC
                    fun.dimrot1(dxf, fun.Polar(p0, pi, ic / 2.0), fun.Polar(p0, 0, ic / 2.0), 180, ic, 0.1, height, arrowsize, exline, "IC=" + Math.Round(ic, 3), "", "");

                    //S
                    fun.dimrot1(dxf, p23, p24, 180, ic * 0.5, 0.1, height, arrowsize, exline, "S=" + Math.Round(s, 3), "", "");

                    /*if (re / scale != 0.001)
                    {
                        RadialDimension dimrad1 = new RadialDimension(arc3, 10, offset, dimensionStyle);//DimensionStyle.Default);
                        dimrad1.UserText = "RE";
                        dxf.AddEntity(dimrad1);
                    }*/

                    fun.dimrot1(dxf, p1, p2, 180, ic, 0.1, height, arrowsize, exline, "LE=" + Math.Round(le, 3), "", "");

                    if (an != 0)
                    {/*
                    Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                    dimang2.UserText = "AN=" + an * 180 / pi + "°";
                    dxf.AddEntity(dimang2);*/
                        fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, 1.2, 1.6, 0.5, "AN=" + an * 180 / pi + "°", "", "");

                    }
                }
                else
                {
                    if (ictc == 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset * 2.5, 180, dimensionStyle);
                        dim1.UserText = String.Format("IC={0}", ic / scale);
                        dxf.AddEntity(dim1);
                    }
                    if (ictc != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset * 2.5, 180, dimensionStyle);
                        dim1.UserText = String.Format("IC={0}", ic / scale, ictc);
                        dxf.AddEntity(dim1);
                    }
                    if (stc == 0)
                    {
                        LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                        dim2.UserText = String.Format("S={0}", s / scale);
                        dxf.AddEntity(dim2);
                    }
                    if (stc != 0)
                    {
                        LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                        dim2.UserText = String.Format("S={0}", s / scale, stc);
                        dxf.AddEntity(dim2);
                    }


                    /*if (re / scale != 0.001)
                    {
                        RadialDimension dimrad1 = new RadialDimension(arc3, 10, offset, dimensionStyle);//DimensionStyle.Default);
                        dimrad1.UserText = String.Format("RE={0}", re / scale);
                        dxf.AddEntity(dimrad1);
                    }*/
                    LinearDimension dim5 = new LinearDimension(new Line(p1, p2), offset * 2.25, 180, dimensionStyle);
                    dim5.UserText = String.Format("LE={0}", Math.Round(le / scale, 2));
                    dxf.AddEntity(dim5);

                    if (an != 0)
                    {
                        /*Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                        dimang2.UserText = "AN=" + an * 180 / pi + "°";
                        dxf.AddEntity(dimang2);*/
                        fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, 1.2, 1.6, 0.5, "AN=" + an * 180 / pi + "°", "", "");


                    }
                }
            }

            //带修光刃三边形刀片----------------------------------------------------------------------------------------------------------
            else
            {
                //点经过修改，去除re赋值影响

                //对称型参数
                Vector2 xiu1 = fun.Polar(p3, -90 * pi / 180, bs);//上
                Vector2 xiu2 = fun.rotatePoint_Changed(p0, xiu1, 120);//左下
                Vector2 xiu3 = fun.rotatePoint_Changed(p0, xiu2, 120);//右下
                Vector2 p1p = fun.Polar(xiu2, epsr / 2.0, ic * 0.2);
                Vector2 p2p = fun.rotatePoint_Changed(p0, p1p, 120);
                Vector2 p3p = fun.rotatePoint_Changed(p0, p1p, -120);
                Vector2 p5 = fun.Polar(p1, 0, bs * Math.Cos(epsr / 2.0) * 2);
                Vector2 p4 = fun.Polar(p1, epsr, bs * Math.Cos(epsr / 2.0) * 2);
                Vector2 p6 = fun.Polar(p2, pi, bs * Math.Cos(epsr / 2.0) * 2);
                Vector2 p7 = fun.Polar(p2, pi - epsr, bs * Math.Cos(epsr / 2.0) * 2);
                Vector2 p9 = fun.Polar(p3, -pi / 2.0 - epsr / 2.0, bs * Math.Cos(epsr / 2.0) * 2);
                Vector2 p8 = fun.Polar(p3, -pi / 2.0 + epsr / 2.0, bs * Math.Cos(epsr / 2.0) * 2);

                Vector2 p20 = fun.Polar(p0, 0, 2 * ic);
                Vector2 p21 = new Vector2(p20.X, xiu1.Y);

                Vector2 p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
                Vector2 p24 = new Vector2(p20.X, p1.Y);
                Vector2 p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));

                Vector2 v1 = fun.Polar(p0, -150 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);
                Vector2 v2 = fun.Polar(p0, -30 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);
                Vector2 v3 = fun.Polar(p0, 90 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);

                /*String insert_choose = Convert.ToString(data["insert_chose"]);

                if (insert_choose.Equals("对称型"))
                {

                }*/

                if (kch == krins)//对称型
                {
                    LwPolyline poly11 = new LwPolyline();
                    poly11.Vertexes.Add(new LwPolylineVertex(p4));
                    poly11.Vertexes.Add(new LwPolylineVertex(xiu2));
                    poly11.Vertexes.Add(new LwPolylineVertex(p5));
                    poly11.Vertexes.Add(new LwPolylineVertex(p6));
                    poly11.Vertexes.Add(new LwPolylineVertex(xiu3));
                    poly11.Vertexes.Add(new LwPolylineVertex(p7));
                    poly11.Vertexes.Add(new LwPolylineVertex(p8));
                    poly11.Vertexes.Add(new LwPolylineVertex(xiu1));
                    poly11.Vertexes.Add(new LwPolylineVertex(p9));
                    poly11.IsClosed = true;
                    fun.PolyFill(dxf, poly11, 0.3, contour);
                }

                else//非对称型
                {
                    if (bs < 2)
                    {
                        xiu1 = fun.Polar(p3, -90 * pi / 180, ic * 0.1);//上
                        p6 = fun.Polar(p2, pi, bs * Math.Cos(epsr / 2.0) * 2);
                        xiu2 = fun.Polar(p6, (180 - krins) * pi / 180 - epsr, bs);//右下
                        xiu3 = fun.mirrorpoint(xiu2, p3, fun.Polar(p3, -90 * pi / 180, le));//左下
                        p7 = fun.Inters(xiu2, fun.Polar(xiu2, pi - epsr - kch * pi / 180, le), p2, p3);
                        p4 = fun.mirrorpoint(p7, p3, fun.Polar(p3, -90 * pi / 180, le));
                        p1p = fun.Polar(xiu2, epsr / 2.0, ic * 0.2);
                        p2p = fun.rotatePoint_Changed(p0, p1p, 120);
                        p3p = fun.rotatePoint_Changed(p0, p1p, -120);

                        p5 = fun.mirrorpoint(p6, p3, fun.Polar(p3, -90 * pi / 180, le));
                        p9 = fun.Polar(p3, -pi / 2.0 - epsr / 2.0, ic * 0.1 * Math.Cos(epsr / 2.0) * 2);
                        p8 = fun.Polar(p3, -pi / 2.0 + epsr / 2.0, ic * 0.1 * Math.Cos(epsr / 2.0) * 2);

                        p20 = fun.Polar(p0, 0, 2 * ic);
                        p21 = new Vector2(p20.X, xiu1.Y);

                        p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
                        p24 = new Vector2(p20.X, p1.Y);
                        p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));

                        LwPolyline poly11 = new LwPolyline();
                        poly11.Vertexes.Add(new LwPolylineVertex(p4));
                        poly11.Vertexes.Add(new LwPolylineVertex(xiu3));
                        poly11.Vertexes.Add(new LwPolylineVertex(p5));
                        poly11.Vertexes.Add(new LwPolylineVertex(p6));
                        poly11.Vertexes.Add(new LwPolylineVertex(xiu2));
                        poly11.Vertexes.Add(new LwPolylineVertex(p7));
                        poly11.Vertexes.Add(new LwPolylineVertex(p8));
                        poly11.Vertexes.Add(new LwPolylineVertex(xiu1));
                        poly11.Vertexes.Add(new LwPolylineVertex(p9));
                        poly11.IsClosed = true;
                        fun.PolyFill(dxf, poly11, 0.3, contour);
                    }
                    else
                    {
                        xiu1 = fun.Polar(p3, -90 * pi / 180, ic * 0.1);//上
                        p6 = fun.Polar(p2, pi, bs * 1.4);
                        xiu2 = fun.Polar(p6, (180 - krins) * pi / 180 - epsr, bs);//右下
                        xiu3 = fun.mirrorpoint(xiu2, p3, fun.Polar(p3, -90 * pi / 180, le));//左下
                        p7 = fun.Inters(xiu2, fun.Polar(xiu2, pi - epsr - kch * pi / 180, le), p2, p3);
                        p4 = fun.mirrorpoint(p7, p3, fun.Polar(p3, -90 * pi / 180, le));
                        p1p = fun.Polar(xiu2, epsr / 2.0, ic * 0.2);
                        p2p = fun.rotatePoint_Changed(p0, p1p, 120);
                        p3p = fun.rotatePoint_Changed(p0, p1p, -120);

                        p5 = fun.mirrorpoint(p6, p3, fun.Polar(p3, -90 * pi / 180, le));
                        p9 = fun.Polar(p3, -pi / 2.0 - epsr / 2.0, ic * 0.1 * Math.Cos(epsr / 2.0) * 2);
                        p8 = fun.Polar(p3, -pi / 2.0 + epsr / 2.0, ic * 0.1 * Math.Cos(epsr / 2.0) * 2);

                        p20 = fun.Polar(p0, 0, 2 * ic);
                        p21 = new Vector2(p20.X, xiu1.Y);

                        p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
                        p24 = new Vector2(p20.X, p1.Y);
                        p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));

                        LwPolyline poly11 = new LwPolyline();
                        poly11.Vertexes.Add(new LwPolylineVertex(p4));
                        poly11.Vertexes.Add(new LwPolylineVertex(xiu3));
                        poly11.Vertexes.Add(new LwPolylineVertex(p5));
                        poly11.Vertexes.Add(new LwPolylineVertex(p6));
                        poly11.Vertexes.Add(new LwPolylineVertex(xiu2));
                        poly11.Vertexes.Add(new LwPolylineVertex(p7));
                        poly11.Vertexes.Add(new LwPolylineVertex(p8));
                        poly11.Vertexes.Add(new LwPolylineVertex(xiu1));
                        poly11.Vertexes.Add(new LwPolylineVertex(p9));
                        poly11.IsClosed = true;
                        fun.PolyFill(dxf, poly11, 0.3, contour);
                    }
                    
                }

                Line line100 = new Line(p8, p9);
                dxf.AddEntity(line100);

                if (cb == 1 || cb == 2)//断屑槽为1或2（默认为0）
                {
                    Line line15 = new Line(v1, v2);
                    line15.Lineweight = Lineweight.W25;
                    line15.Layer = additionalline;
                    dxf.AddEntity(line15);
                    Line line16 = new Line(v2, v3);
                    line16.Lineweight = Lineweight.W25;
                    line16.Layer = additionalline;
                    dxf.AddEntity(line16);
                    Line line17 = new Line(v1, v3);
                    line17.Lineweight = Lineweight.W25;
                    line17.Layer = additionalline;
                    dxf.AddEntity(line17);
                }

                insert.inserthole1(dxf, p0, v2, v3, p20, p21, scale, data);

                //Arc arc3 = fun.DrawArc(p8, p3p, p9);

                Line line12 = new Line(p1, p2);
                line12.Lineweight = Lineweight.W25;
                line12.Layer = additionalline;
                dxf.AddEntity(line12);
                Line line13 = new Line(p2, p3);
                line13.Lineweight = Lineweight.W25;
                line13.Layer = additionalline;
                dxf.AddEntity(line13);
                Line line14 = new Line(p1, p3);
                line14.Lineweight = Lineweight.W25;
                line14.Layer = additionalline;
                dxf.AddEntity(line14);



                Line cenline1 = new Line(fun.Polar(p0, pi, ic / 2 * 1.5), fun.Polar(p0, 0, ic / 2 * 1.5));
                Line cenline2 = new Line(fun.Polar(p0, 0.5 * pi, ic * 1.1), fun.Polar(p0, -0.5 * pi, ic / 2 * 1.5));
                Line cenline3 = new Line(fun.Polar(p20, 0, 3), fun.Polar(p20, pi, s + 3));
                Circle dotcircle1 = new Circle(p0, ic / 2);
                cenline1.Layer = center;
                cenline2.Layer = center;
                cenline3.Layer = center;
                dotcircle1.Layer = refin;
                cenline1.Linetype = Linetype.Center;
                cenline2.Linetype = Linetype.Center;
                cenline3.Linetype = Linetype.Center;
                dotcircle1.Linetype = Linetype.DashDot;
                dxf.AddEntity(cenline1);
                dxf.AddEntity(cenline2);
                dxf.AddEntity(cenline3);
                dxf.AddEntity(dotcircle1);

                //fun.jz(dxf, fun.Polar(fun.Polar(p0, 0, ic / 2), -90 * pi / 180, 25), 0, 3, "A");

                //标注---------------------------------------------------------------------------
                double height = 1 * scale;
                double arrowsize = 1 * scale;
                double exline = 0.5 * scale;
                DimensionStyle dimensionStyle = new DimensionStyle("sd");
                dimensionStyle.ArrowSize = 1.6;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = 0.5;

                if (DIM == 0)
                {
                    //IC
                    fun.dimrot1(dxf, fun.Polar(p0, pi, ic / 2.0), fun.Polar(p0, 0, ic / 2.0), 180, ic, 0.1, height, arrowsize, exline, "IC=" + Math.Round(ic, 3), "", "");

                    //S
                    fun.dimrot1(dxf, p23, p24, 180, ic * 0.5, 0.1, height, arrowsize, exline, "S=" + Math.Round(s, 3), "", "");

                    /*if (re / scale != 0.001)
                    {
                        RadialDimension dimrad1 = new RadialDimension(arc3, 10, offset, dimensionStyle);//DimensionStyle.Default);
                        dimrad1.UserText = "RE";
                        dxf.AddEntity(dimrad1);
                    }*/

                    fun.dimrot1(dxf, p1, p2, 180, ic, 0.1, height, arrowsize, exline, "LE=" + Math.Round(le, 3), "", "");

                    if (an != 0)
                    {/*
                    Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                    dimang2.UserText = "AN=" + an * 180 / pi + "°";
                    dxf.AddEntity(dimang2);*/
                        fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, 1.2, 1.6, 0.5, "AN=" + an * 180 / pi + "°", "", "");

                    }
                }
                else
                {
                    if (ictc == 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset * 2.5, 180, dimensionStyle);
                        dim1.UserText = String.Format("IC={0}", ic / scale);
                        dxf.AddEntity(dim1);
                    }
                    if (ictc != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset * 2.5, 180, dimensionStyle);
                        dim1.UserText = String.Format("IC={0}", ic / scale, ictc);
                        dxf.AddEntity(dim1);
                    }
                    if (stc == 0)
                    {
                        LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                        dim2.UserText = String.Format("S={0}", s / scale);
                        dxf.AddEntity(dim2);
                    }
                    if (stc != 0)
                    {
                        LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                        dim2.UserText = String.Format("S={0}", s / scale, stc);
                        dxf.AddEntity(dim2);
                    }


                    /*if (re / scale != 0.001)
                    {
                        RadialDimension dimrad1 = new RadialDimension(arc3, 10, offset, dimensionStyle);//DimensionStyle.Default);
                        dimrad1.UserText = String.Format("RE={0}", re / scale);
                        dxf.AddEntity(dimrad1);
                    }*/
                    LinearDimension dim5 = new LinearDimension(new Line(p1, p2), offset * 2.25, 180, dimensionStyle);
                    dim5.UserText = String.Format("LE={0}", Math.Round(le / scale, 2));
                    dxf.AddEntity(dim5);

                    if (an != 0)
                    {
                        /*Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                        dimang2.UserText = "AN=" + an * 180 / pi + "°";
                        dxf.AddEntity(dimang2);*/
                        fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, 1.2, 1.6, 0.5, "AN=" + an * 180 / pi + "°", "", "");


                    }
                }
            }

            

            //图框
            double isframe = Convert.ToDouble(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);

            if (isframe_chose.Equals("无"))
            {
            }

            if (isframe_chose.Equals("0"))
            {
                Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            if (isframe_chose.Equals("1"))
            {
                Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            if (isframe_chose.Equals("2"))
            {
                Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            if (isframe_chose.Equals("3"))
            {
                Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            if (isframe_chose.Equals("4X"))
            {
                Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            if (isframe_chose.Equals("4Y"))
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
